<template>
    <view class="page-main">
        <liu-indexed-list :dataList="dataList" @click="click">
		</liu-indexed-list>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                dataList: []
            }
        },
		onLoad(){
			this.queryMyFriends();
		},
		onPullDownRefresh() {
			//下拉刷新
			this.queryMyFriends();
		},
        methods: {
            //点击列表回调事件
            click(e) {
                console.log('点击列表回调：', e)
				
				//跳转到聊天页面，并且将好友的信息带过去
				uni.navigateTo({
					url: "/pages/chat/chat?friendInfo=" + JSON.stringify(e)
				})
            },
			//查询我的好友列表
			queryMyFriends(){
				this.$.ajax({
					url: "/friendship/myFriends",
					success: (result) => {
						
						//对头像做一个预处理
						result.forEach((user) => {
							
							//缓存好友信息
							/**
							 * {
									"id": 1,
									"name": "小明",
									"phone": "test1",
									"img": "e11649c3-7c11-4571-9185-f30d6cf84ba2"
								}
							 */
							uni.setStorageSync("friendsInfo_" + user.id, {
								id: user.id,
								nickname: user.name,
								header: user.img
							});
							
							//转换成图片地址
							user.img = this.$.getImg(user.img);
						});
						this.dataList = result;
						
						//关闭下拉刷新
						uni.stopPullDownRefresh();
					}
				});
			}
        }
    }
</script>

<style>

</style>
